// -----------------------------------------------
// Author:     code34 nicolas_boiteux@yahoo.fr
// Edited by:  Neumatic
// Warcontext: Create a mine field at road position (near position parameter)
// -----------------------------------------------

private [
	"_number",
	"_marker",
	"_mine",
	"_position",
	"_roads"
];

_position = _this select 0;

_number = (random 5);

WC_fnc_PDB_MF = {
	private ["_bearing","_distance","_pos"];
	_pos      = _this select 0;
	_bearing  = _this select 1;
	_distance = _this select 2;
	[(_pos select 0) + (_distance * (sin _bearing)), (_pos select 1) + (_distance * (cos _bearing))];
};

_roads = _position nearRoads 400;
{
	if !((count (roadsConnectedTo _x) > 1) and (count (nearestObjects [_x, ["House"], 20]) > 0)) then {
		_roads = _roads - [_x];
	};
} foreach _roads;

_position = position (_roads call BIS_fnc_selectRandom);

//A3 TODO: Mines in A3?
if (count _position > 0) then {
	_marker = [format ["mrkminefield%1", wcminefieldindex], 0.5, _position, "ColorRed", "ICON", "FDIAGONAL", "hd_warning", 0, "", false] call WC_fnc_createmarkerlocal;
	wcambiantmarker = wcambiantmarker + [_marker];
	wcminefieldindex = wcminefieldindex + 1;

	for "_x" from 0 to _number do {
		_mine = createMine ["MineMine", _position, [], 10];
		wcobjecttodelete = wcobjecttodelete + [_mine];
	};

	diag_log format ["WARCONTEXT: GENERATE A MINEFIELD AT POSITION %1", _position];
};